package com.xxx.yuedong.mine.controller;

import cn.hutool.json.JSONUtil;
import com.xxx.yuedong.common.R;
import com.xxx.yuedong.mine.controller.form.*;
import com.xxx.yuedong.mine.service.PermissionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.HashMap;

@RequestMapping("/permission")
@Api(tags = "权限相关接口")
@Slf4j
@RestController
public class PermissionController {
    @Autowired
    private PermissionService permissionService;

    @PostMapping("/list")
    @ApiOperation("分页查询权限列表")
    public R list(@Valid @RequestBody SearchPermissionListForm form){
        HashMap param = JSONUtil.parse(form).toBean(HashMap.class);
        return permissionService.list(param);
    }

    @PostMapping("/insert")
    @ApiOperation("新增权限")
    public R insert(@Valid @RequestBody InsertPermissionForm form){
        HashMap param = JSONUtil.parse(form).toBean(HashMap.class);
        return permissionService.insert(param);
    }

    @PostMapping("/update")
    @ApiOperation("更新权限")
    public R update(@Valid @RequestBody UpdatePermissionForm form){
        HashMap param = JSONUtil.parse(form).toBean(HashMap.class);
        return permissionService.update(param);
    }

    @PostMapping("/searchPermissionInfo")
    @ApiOperation("查询权限信息")
    public R searchPermissionInfo(@Valid @RequestBody SearchPermissionForm form){
        return permissionService.searchPermissionInfo(form.getId());
    }

    @PostMapping("/getPermissionList")
    @ApiOperation("权限列表")
    public R getPermissionList(){
        return permissionService.getPermissionList();
    }

    @PostMapping("/delete")
    @ApiOperation("删除权限")
    public R delete(@Valid @RequestBody DeletePermissionByIdsForm form){
        return permissionService.delete(form.getIds());
    }


}
